$(function(){

	function GetQueryString (name) { //获取指定name的url参数
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return (r[2]);
        return null;
    }
    function Toast (txt){
        var toastHtml = '<div class="tk_info" id="tkInfo"></div>';
        var toast = $('body #tkInfo');
        if (toast.length) {
            toast.html(txt).show();
        }else{
            $('body').append(toastHtml);
            $('body #tkInfo').html(txt).show();
        }
        setTimeout(function(){
          $('body #tkInfo').hide();
        },3000)
    }

    const id = GetQueryString('id');
    const userId = GetQueryString('userId');
    const token = GetQueryString('token');
    const key =  'http://'+ GetQueryString('invokeDomain');;

    //返回状态
    function state(key){
        var txt = '';
        switch(key) {
             case 0:
                txt = '待审核'
                break;
             case 1:
                 txt = '成功'
                break;
             default:
                txt = '驳回'
        };
        return txt
    }

    function getUserInfo(){
        $.ajax({
            type:'get',
            dataType: 'json',
            url:key+'/system/api/transfer/transferStatus',
            data: {
                'userId':userId,
                'token':token,
                'id':id
            },
            //请求成功时执行
            success: function(v) {
                const code = v.code;
                const msg = v.msg;
                const data = v.data;
                if (code == 0) {
                    var states = state(data.state);
                    $('.state').html(states)
                   $('#userImg').attr('src',data.image?(key+data.image):'./image/icon-dian1.png')
                   $('#userName').html(data.wechatName||'--');
                   $('#channl').html(data.channel||'--')
                   $('#txMoney').html(data.txMoney)
                   $('#createTime').html(data.createTime);
                   $('.finishTime').html(data.finishTime);
                   if (data.channel == '微信') {
                    $('#info').html('微信>我>零钱>零钱明细，如有名称“企业付款”的数据。即提现到账成功！')
                   }else{
                    $('#info').html('支付宝>我的>账单 内查看到商家打款记录，即表示提现成功！')
                   }
                } else {
                    // 异常处理
                   Toast(msg)
                }
            },
            //请求失败遇到异常触发
            error: function(d) {
                Toast('网络错误')
                // console.log(d.msg);
                // window.webkit.messageHandlers.MJLogin.postMessage(null)
            }
        })
    }
    getUserInfo()
})